package net.hn.hnms.sys.common.web.core;

import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;
import java.util.Locale;

/**
 * 获取请求头国际化信息
 *
 * @author Lion Li
 */
public class I18nLocaleResolver implements LocaleResolver {

    @Override
    public Locale resolveLocale(HttpServletRequest httpServletRequest) {
//        String language = httpServletRequest.getHeader("Accept-Language");
        Locale locale = Locale.getDefault();
//        Enumeration<Locale> locales = httpServletRequest.getLocales();
//        Locale locale1 = httpServletRequest.getLocale();
//        if (language != null && language.length() > 0) {
//            String[] split = language.split("-");
//            locale = new Locale(split[0], split[1]);
//        }
        return httpServletRequest.getLocale() == null ? locale : httpServletRequest.getLocale();
    }

    @Override
    public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {

    }
}
